using System;
using System.Runtime.InteropServices;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;

namespace CodeCounsel.SharePoint2010.DigiD.Features.Farm
{
    [Guid("7a5eb20d-4549-43bc-9630-5022abcebb11")]
    public class FarmEventReceiver : SPFeatureReceiver
    {
        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            SPWebService adminService = (SPWebService)properties.Feature.Parent;

            DigiDService service = adminService.Farm.Services.GetValue<DigiDService>();
            if (service == null)
            {
                service = new DigiDService(adminService.Farm);
                service.Update();
            }
        }

        public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
        {
            SPWebService adminService = (SPWebService)properties.Feature.Parent;

            DigiDService service = adminService.Farm.Services.GetValue<DigiDService>();
            if (service != null)
            {
                service.Delete();
            }
        }
    }
}
